package sort;

/**
 * Created with IntelliJ IDEA.
 * Description: 冒泡排序
 * User: Li_yizYa
 * Date: 2025/9/8
 * Time: 22:32
 */
// 6  5  4  4  3  1  2  10  8
//
public class BubbleSort {
    public static void bubbleSort(int[] nums) {
        if (nums == null || nums.length == 0) {
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            int flag = 0;
            for (int j = 0; j < nums.length - i - 1; j++) {
                if (nums[j] > nums[j + 1]) {
                    int tmp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = tmp;
                    flag = 1;
                }
            }
            if (flag == 0) {
                break;
            }
        }
    }
    public static void main(String[] args) {
        int[] nums = {6,5,4,4,3,1,2,10,8};
        bubbleSort(nums);
        for (int num : nums) {
            System.out.print(num + " ");
        }
    }
}
